package com.qianli.user.facade.query.impl.feature;

import com.fqgj.common.api.Response;
import com.qianli.user.application.UserFeatureApplication;
import com.qianli.user.domain.model.UserFeatureModel;
import com.qianli.user.facade.query.feature.UserFeatureQueryServiceFacade;
import com.qianli.user.ro.BaseRO;
import com.qianli.user.ro.UserStateCode;
import com.qianli.user.ro.feature.FeatureTagRO;
import com.qianli.user.ro.feature.UserFeatureTagRO;
import com.qianli.user.ro.query.UserBaseQueryRO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * name:特征查询
 * auth:ting.li@qianli-inc.com
 * date:2018/1/9 15:32
 * version: v1.0.0
 **/
@Service("userFeatureQueryServiceFacade")
public class UserFeatureQueryServiceFacadeImpl implements UserFeatureQueryServiceFacade{

    private static final Logger LOGGER = LoggerFactory.getLogger(UserFeatureQueryServiceFacade.class);

    @Autowired
    private UserFeatureApplication userFeatureApplication;

    /**
     * 查询该app的所有标签
     * @param base
     * @return
     */
    @Override
    public Response<List<FeatureTagRO>> queryAllFeatureTags(BaseRO base) {
        if(null == base){
            LOGGER.info("UserFeatureQueryServiceFacade.queryAllFeatureTags param can not be null");
            return Response.error(UserStateCode.PARAMETER_LACK);
        }
        if(null == base.getBiz()|| null == base.getAppCode()){
            LOGGER.info("UserFeatureQueryServiceFacade.queryAllFeatureTags param can biz and appCode not be null");
            return Response.error(UserStateCode.PARAMETER_LACK);
        }
        List<FeatureTagRO> tagROEs = userFeatureApplication.queryAllFeatureTags(base.getAppCode(),base.getBiz());
        return Response.ok(tagROEs);
    }

    /**
     * 查询用户标签
     * @param queryRO
     * @return
     */
    @Override
    public Response<List<UserFeatureTagRO>> queryUserFeatureTags(UserBaseQueryRO queryRO) {
        if(null == queryRO){
            LOGGER.info("UserFeatureQueryServiceFacade.queryUserFeatureTags param can not be null");
            return Response.error(UserStateCode.PARAMETER_LACK);
        }
        if(null == queryRO.getBiz()|| null == queryRO.getAppCode()){
            LOGGER.info("UserFeatureQueryServiceFacade.queryUserFeatureTags param can biz and appCode not be null");
            return Response.error(UserStateCode.PARAMETER_LACK);
        }
        if(null == queryRO.getUserCode()){
            LOGGER.info("UserFeatureQueryServiceFacade.queryUserFeatureTags param can userCode not be null");
            return Response.error(UserStateCode.PARAMETER_LACK);
        }
        UserFeatureModel model = new UserFeatureModel();
        model.setUserCode(queryRO.getUserCode());
        model.setAppCode(queryRO.getAppCode());
        model.setBiz(queryRO.getBiz());
        List<UserFeatureTagRO> userFeatureTagROEs = userFeatureApplication.load(model);
        return Response.ok(userFeatureTagROEs);
    }
}
